package com.house365.core.thirdpart.auth;

import java.io.IOException;

import android.content.Context;

import com.house365.core.thirdpart.auth.qqwb.QQWeiboApiRequest;
import com.house365.core.thirdpart.auth.sina.SinaWeiboApiRequest;

/**
 *@author py
 *@date 2012-11-6
 *@comment
 */
public class WeiboAsyncRequest {
	private Thirdpart weibo;
	private WeiboHttpAPi httpApi;

	public WeiboAsyncRequest(Thirdpart weibo,Context context) {
		this.weibo = weibo;
		this.httpApi = new WeiboHttpAPi(context);
	}

	public void request(final Context context,final AppKeyInfo appkeyInfo, final String content, final String pic,
			final RequestListener listener) {
		new Thread() {
			@Override
			public void run() {
				try {
					String resp =null;
					WeiboApiRequest api;
					if(appkeyInfo.getType() == Thirdpart.TYPE_QQ_WEIBO){
						api = new QQWeiboApiRequest();
						resp= api.post(httpApi, weibo,appkeyInfo, content, pic,listener);
					}else if(appkeyInfo.getType() == Thirdpart.TYPE_SINA_WEIBO){
						api = new SinaWeiboApiRequest();
						resp= api.post(httpApi, weibo,appkeyInfo, content, pic,listener);
					}else{
						api = new SinaWeiboApiRequest();
						resp= api.post(httpApi, weibo,appkeyInfo, content, pic,listener);
					}
					
					listener.onComplete(resp);
				} catch (WeiboException e) {
					listener.onError(e);
				}
			}
		}.start();

	}
	
    public static interface RequestListener {

        public void onComplete(String response);

        public void onIOException(IOException e);

        public void onError(WeiboException e);

    }
}
